import { createRouter, createWebHistory } from 'vue-router';
import Login from '../components/UserLogin.vue';
// 假设这是你的主页组件，你可以根据实际情况替换
import Home from '../components/HelloWorld.vue'; 

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/',
    name: 'Home',
    component: Home
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 路由守卫，用于验证用户是否登录
router.beforeEach((to, from, next) => {
  const isLoggedIn = false; // 这里可以根据实际情况判断用户是否登录
  if (to.name !== 'Login' && !isLoggedIn) {
    next({ name: 'Login' });
  } else {
    next();
  }
});

export default router;